package com.baby.security.config;


import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.DispatcherType;
import java.util.EnumSet;

/**
 * @author 猪猪
 * @since 2022/6/16
 */
@Configuration
public class FilterConfig {

    /**
     * 过滤器代理注册器
     *
     * DelegatingFilterProxyRegistrationBean 通过传入的proxyFilter名字,在WebApplicationContext查找该Fillter Bean,
     * 并通过DelegatingFilterProxy生成基于该Bean的代理Filter对象
     */
    @Bean
    public DelegatingFilterProxyRegistrationBean delegatingFilterProxyRegistrationBean() {
        //将我们创建的过滤器加入过滤器注册器中 就可以再DelegatingFilterProxyRegistrationBean类中的getFilter（）方法查看过滤器是否加载成功
        DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean("myFilter");
        registration.setOrder(100);//顺序
        registration.addUrlPatterns("/*");
        registration.setDispatcherTypes(DispatcherType.ASYNC, DispatcherType.ERROR,
                DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST);
        return registration;
    }
}
